/*
 * Copyright 2011-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

/*
 * http://localhost:8080/sysmgmt/user/select?page=1&rows=3
 *
 * {
 *     "rows": [
 *         {
 *             "email": "a@b.com",
 *             "id": "000001",
 *             "userNo": "000001",
 *             "username": "Lee000001"
 *         },
 *         {
 *             "email": "a@b.com",
 *             "id": "000002",
 *             "userNo": "000002",
 *             "username": "Lee000002"
 *         },
 *         {
 *             "email": "a@b.com",
 *             "id": "000003",
 *             "userNo": "000003",
 *             "username": "Lee000003"
 *         }
 *     ],
 *     "total": 20
 * }
 */

package me.ijleex.mgmt.framework.page;

import java.util.Collections;
import java.util.List;

import me.ijleex.mgmt.framework.entity.EntitySupport;

/**
 * 分页参数与数据
 *
 * @param <T> 需要分页的对象——即 MVC 中的模型，如 User、Menu 等。
 * @author me
 * @since 2015-10-23 15:13:30 新建
 */
public final class Page<T extends EntitySupport> {

    // -------------------- 分页响应参数 --------------------
    /**
     * 数据总条数
     */
    private final long total;
    /**
     * 数据
     */
    private final List<T> rows;

    public Page(long total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }

    public long getTotal() {
        return this.total;
    }

    public List<T> getRows() {
        if (this.rows == null) {
            return Collections.emptyList();
        }
        return Collections.unmodifiableList(this.rows);
    }

    /**
     * 分页信息
     *
     * @author liym
     * @version 2016-09-14 18:03:53
     */
    @Override
    public String toString() {
        return "Page total: " + this.total + ", rows: " + (this.rows == null ? 0 : this.rows.size());
    }

}
